package com.gemme.gemme.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.Button;
import android.widget.RelativeLayout;

import com.gemme.gemme.R;

public class CommentView extends RelativeLayout {
    private Context context;
    private OnChangeLIstener onChangeLIstener;

    public CommentView(Context context) {
        this(context,null);
    }

    public CommentView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public CommentView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        initView();
    }
    CommentCheckBox iv_1;
    CommentCheckBox iv_2;
    CommentCheckBox iv_3;
    CommentCheckBox iv_4;
    CommentCheckBox iv_5;
    int level = 0;
    private void initView() {
        LayoutInflater.from(context).inflate(R.layout.conment_view,this);
//        RelativeLayout

        iv_1 = findViewById(R.id.iv_1);
        iv_2 = findViewById(R.id.iv_2);
        iv_3 = findViewById(R.id.iv_3);
        iv_4 = findViewById(R.id.iv_4);
        iv_5 = findViewById(R.id.iv_5);

        /*iv_1
        iv_2.setEnabled(false);
        iv_3.setEnabled(false);
        iv_4.setEnabled(false);
        iv_5.setEnabled(false);*/

        iv_1.setOnChangeLIstener(new OnChangeLIstener() {
            @Override
            public void onChangeLIstener() {
                iv_1.setChecked(true);
                iv_2.setChecked(false);
                iv_3.setChecked(false);
                iv_4.setChecked(false);
                iv_5.setChecked(false);
                level = 1;
                if(onChangeLIstener != null)
                    onChangeLIstener.onChangeLIstener();
            }
        });
        iv_2.setOnChangeLIstener(new OnChangeLIstener() {
            @Override
            public void onChangeLIstener() {
                iv_1.setChecked(true);
                iv_2.setChecked(true);
                iv_3.setChecked(false);
                iv_4.setChecked(false);
                iv_5.setChecked(false);
                level = 2;
                if(onChangeLIstener != null)
                    onChangeLIstener.onChangeLIstener();
            }
        });
        iv_3.setOnChangeLIstener(new OnChangeLIstener() {
            @Override
            public void onChangeLIstener() {
                iv_1.setChecked(true);
                iv_2.setChecked(true);
                iv_3.setChecked(true);
                iv_4.setChecked(false);
                iv_5.setChecked(false);
                level = 3;
                if(onChangeLIstener != null)
                    onChangeLIstener.onChangeLIstener();
            }
        });
        iv_4.setOnChangeLIstener(new OnChangeLIstener() {
            @Override
            public void onChangeLIstener() {
                iv_1.setChecked(true);
                iv_2.setChecked(true);
                iv_3.setChecked(true);
                iv_4.setChecked(true);
                iv_5.setChecked(false);
                level = 4;
                if(onChangeLIstener != null)
                    onChangeLIstener.onChangeLIstener();
            }
        });
        iv_5.setOnChangeLIstener(new OnChangeLIstener() {
            @Override
            public void onChangeLIstener() {
                iv_1.setChecked(true);
                iv_2.setChecked(true);
                iv_3.setChecked(true);
                iv_4.setChecked(true);
                iv_5.setChecked(true);
                level = 5;
                if(onChangeLIstener != null)
                    onChangeLIstener.onChangeLIstener();
            }
        });
    }

    public int getLevel(){
        return level;
    }

    public String getLevelStr(){
        String str = "";
        switch (level){
            case 1:
                str = "非常差";
                break;

            case 2:
                str = "差";
                break;

            case 3:
                str = "一般";
                break;

            case 4:
                str = "好";
                break;
            case 5:
                str = "非常好";
                break;

        }
       return str;

    }

    public void setOnChangeLIstener(OnChangeLIstener onChangeLIstener){

        this.onChangeLIstener = onChangeLIstener;
    }


}
